# _*_coding:utf-8 _*_
# @Time    :2022/3/19 8:39
# @Author  :gxp
# @FileName: calculate.py
# @Software: PyCharm

import random

sign = ['+', '-', '*', '/']

# 生成随机数


#测试

def random_num():
    # 两个运算符号
    sign_index = random.randint(0, 3)
    sign_index2 = random.randint(0, 3)
    # 三个随机数
    num1 = random.randint(0, 100)
    num2 = random.randint(1, 100)
    num3 = random.randint(1, 100)
    # 括号的信号
    signal = random.randint(0, 2)
    return sign_index, sign_index2, num1, num2, num3, signal

# 根据信号选择计算的格式


def calculateStr(sign_index, sign_index2, num1, num2, num3, signal):
    if signal == 0:
        str1 = str(num1) + sign[sign_index] + \
            str(num2) + sign[sign_index2] + str(num3)
    elif signal == 1:
        str1 = '(' + str(num1) + sign[sign_index] + \
            str(num2) + ')' + sign[sign_index2] + str(num3)
    else:
        str1 = str(num1) + sign[sign_index] + '(' + \
            str(num2) + sign[sign_index2] + str(num3) + ")"
    return str1

# 计算


def calculate():
    # 计数
    calculate_num = 0
    # 记录数学题目
    member = []
    while True:
        sign_index, sign_index2, num1, num2, num3, signal = random_num()
        str1 = calculateStr(sign_index, sign_index2, num1, num2, num3, signal)
        result = eval(str1)
        # 判断数学题是否已经存在
        if str1 in member:
            continue
        else:
            member.append(str1)
            # 判断是否为整数
            if isinstance(result, int):
                if result >= 0 and result <= 100:
                    print(str1 + " = ? ")
                    calculate_num += 1
                    answer = input("输入您的结果：")
                    if str(answer) == str(result):
                        print("congratulations!")
                    else:
                        print("you are wrong!")
        if calculate_num >= 10:
            break


if __name__ == '__main__':
    calculate()
